package com.wanjia.seal.manager.controller;

import com.alibaba.fastjson.JSONObject;
import com.wanjia.seal.manager.annotation.LoginToken;
import com.wanjia.seal.manager.controller.ex.DataNotFoundException;
import com.wanjia.seal.manager.entity.BankInfoTB;
import com.wanjia.seal.manager.entity.ResultLog;
import com.wanjia.seal.manager.entity.ResultLogVo;
import com.wanjia.seal.manager.mapper.BankInfoTBMapper;
import com.wanjia.seal.manager.mapper.ResultLogMapper;
import com.wanjia.seal.manager.utils.JsonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/api")
@Api(tags = "验印结果日志表")
public class ResultLogController extends BaseController{

    @Autowired
    ResultLogMapper resultLogMapper;
    @Autowired
    BankInfoTBMapper bankInfoTBMapper;


    @ResponseBody
    @PostMapping("/getResultlog")
    @LoginToken
    public JsonResult<Object> findAllResultLog(@RequestBody ResultLog resultLog, String startTime, String endTime, Integer pageNum, Integer pageSize){
        String Account = resultLog.getAccount();
        String Bank= resultLog.getBank();
        String OperatorID = resultLog.getOperatorID();
        String CheckID = resultLog.getCheckID();
        String CheckType = resultLog.getCheckType();
        String method = resultLog.getMethod();
        String sealResult = resultLog.getSealResult();
        List<String> list = Arrays.asList(Bank.split(","));

        if (startTime==null){
            startTime ="1988-01-01";
        }
        if (endTime==null){
            endTime="2099-01-01";
        }
        if (pageNum != null){
            List<ResultLogVo> result = resultLogMapper.findByResultLog(method,sealResult,Account, list, OperatorID, startTime, endTime, CheckID, CheckType, pageNum, pageSize);
            List<ResultLogVo> result2 = resultLogMapper.findByResultLogs(method,sealResult,Account, list, OperatorID, startTime, endTime, CheckID, CheckType);
            int size = result2.size();
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("total",size);
            jsonObject.put("ResultLog",result);
            return new JsonResult<>(OK,jsonObject);
        }else {
            List<ResultLogVo> result = resultLogMapper.findByResultLogs(method,sealResult,Account, list, OperatorID, startTime, endTime, CheckID, CheckType);
            int size = result.size();
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("total",size);
            jsonObject.put("ResultLog",result);
            return new JsonResult<>(OK,jsonObject);
        }
    }
}
